package com.lotus.lqmp.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lotus.idaas.sdk.common.UserInfoContext;
import com.lotus.lqmp.service.common.utils.UuidUtil;
import com.lotus.lqmp.service.dao.entity.ReviewPlanEcuMasterDataDo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lotus.lqmp.service.dao.EcuReviewStageRecordMapper;
import com.lotus.lqmp.service.dao.entity.EcuReviewStageRecordDo;
import com.lotus.lqmp.service.service.EcuReviewStageRecordService;
import com.lotus.platform.common.biz.impl.BaseBiz;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * ECU评审记录表Service业务层处理
 *
 * @author Shiheng.Liu1
 * @date 2022-03-29
 */
@Service
public class EcuReviewStageRecordServiceImpl extends BaseBiz<EcuReviewStageRecordMapper, EcuReviewStageRecordDo>  implements EcuReviewStageRecordService{
    @Autowired
    private EcuReviewStageRecordMapper ecuReviewStageRecordMapper;

    @Override
    public void logicBatchDeleteByMasterIds(List<Long> masterEcuDataIds) {
        QueryWrapper<EcuReviewStageRecordDo> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("review_plan_ecu_basic_info_id", masterEcuDataIds);
        List<EcuReviewStageRecordDo> stageRecordDos = ecuReviewStageRecordMapper.selectList(queryWrapper);
        if (CollectionUtils.isEmpty(stageRecordDos)) {
            return;
        }

        stageRecordDos.forEach(curr -> {
            curr.setEditor(UserInfoContext.getUserInfo().getEmployeeNo());
            curr.setEcuReviewStatus(99);
        });
        updateBatchById(stageRecordDos);
    }

    @Override
    public void restoreStageRecord(List<Long> masterEcuDataIds) {
        QueryWrapper<EcuReviewStageRecordDo> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("review_plan_ecu_basic_info_id", masterEcuDataIds);
        List<EcuReviewStageRecordDo> stageRecordDos = ecuReviewStageRecordMapper.selectList(queryWrapper);
        if (CollectionUtils.isEmpty(stageRecordDos)) {
            return;
        }

        //todo 删除之前的评审状态？
        stageRecordDos.forEach(curr -> {
            curr.setEcuReviewStatus(0);
            curr.setEditor(UserInfoContext.getUserInfo().getEmployeeNo());
        });
        updateBatchById(stageRecordDos);
    }
}
